#include "BlockQueue.hpp"
#include <iostream>
#include <pthread.h>
#include <unistd.h>
#include "Task.hpp"
#include "RingQueue.hpp"
void *producer(void *arg)
{

    RingQueue<int> *bq = static_cast<RingQueue<int> *>(arg);
    std::cout << "Producer is producing items..." << std::endl;
    // 生产逻辑省略
    int data = 1;
    while (true)
    {
        //  sleep(1); // 模拟生产耗时
        std::cout << "Produce 任务:" << std::endl;

        bq->Equeue(data);
        data++;
    }
    return nullptr;
}
void *consumer(void *arg)
{

    RingQueue<int> *bq = static_cast<RingQueue<int> *>(arg);
    std::cout << "Consumer is consuming items..." << std::endl;
    // 消费逻辑省略
    while (true)
    {
        sleep(1); // 模拟消费耗时
        int t = 0;
        bq->Pop(&t);
        std::cout << "Consume 消费一个数据: " << t << std::endl;

    }
    return nullptr;
}

int main()
{
    RingQueue<int> *bq = new RingQueue<int>(); // 申请阻塞队列

    // 构建生产消费
    pthread_t p1[1], c1[1];
    pthread_create(p1, nullptr, producer, (void *)bq);

    pthread_create(c1, nullptr, consumer, (void *)bq);

    pthread_join(p1[0], nullptr);

    pthread_join(c1[0], nullptr);

    return 0;
}